﻿using EnvironSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SkillSystem
{
    public class DamageTrigger:IDamageTrigger
    {
        private DamageOpportunityPorcesser timeProcesser;

        private DamageAreaProcesser areaProcesser;

        protected ISkillTransmitter transmitter;

        public DamageTrigger(ISkillTransmitter transmitter)
        {
            this.transmitter = transmitter;
            timeProcesser = new DamageOpportunityPorcesser(transmitter);
            areaProcesser = new DamageAreaProcesser(transmitter);
            Init();
        }

        void Init()
        {
            timeProcesser.Init(OnDamage);
        }

        private void OnDamage()
        {
            Dictionary<AreaType,IAreaArgs> areas =areaProcesser.GetDamageArea();
            foreach (var item in areas)
            {
                IEnvironmentElement[] elements =EnvironmentSystemFacade.Inst.GetElementsInArea(item.Key, item.Value);
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i] is ISkillReceiver)
                    {
                        ((ISkillReceiver)elements[i]).ReceiverSkillItem(transmitter.CurSkillItem);
                    }
                }
            }
        }

    }
}
